class PixieC:
	def blockToStage(self, block):
		blockToStageMap = {"Blink" : "BlinkStage(PIXIE_PRIORITY_NORM, 1)"}
		return blockToStageMap[block]
	def writeNesCFile(self,links, blocks):
		header =  "#include 'Pixie.h'\n\n"
		header += "configuration " + "OpalC" + "\n"
		header += "{ \n"
		header += "} \n \n"
		
		implementation = "implementation\n" + "{\n"
		implementation += writeComponentDefs(blocks)
		implementation += writeWiring(links)
		implementation += "}\n"

		doc = header + implementation
		return doc
	def writeComponentDefs(self, blocks):
		components = []
		for component in blocks:
			line = "components new " + self.blockToStage(component)
			line += " as " component.module + component.id + ";\n"
		out = ""
		for comp_def in components:
			out += comp_def
			out += "\n"
		return components
	def writeWiring(self, links):
		output = ""
		for link in links:
			output += link.src.module + link.src.id + ".Output"
			output += " -> "
			output += link.dest.module + link.dest.id + ".Input"
			output += ";"
			output += "\n"
		return output